/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controleur;

import ia_multiagent1.Agent;
import ia_multiagent1.LogAgent;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextField;
import vue.JPanelGrid;

/**
 *
 * @author Christine
 */
public class ControleurParcours implements Runnable{
    
    private Agent agent;
    private Vector<LogAgent> log;
    private JPanelGrid grid;
    private JTextField txt;
    
    public ControleurParcours(Agent agent, Vector<LogAgent> log, JPanelGrid grid, JTextField txt){
        this.agent= agent;
        this.log = log;
        this.grid = grid;
        this.txt = txt;
    }

    public void run() {
        // Reconstitution des mouvements de l'agent
        for (int i=1; i<log.size(); i++){
            agent.setX(log.elementAt(i).getX());
            agent.setY(log.elementAt(i).getY());
            grid.repaint();
            try {
                Thread.sleep(Integer.parseInt(txt.getText()));
            } catch (InterruptedException ex) {
                Logger.getLogger(ControleurParcours.class.getName()).log(Level.SEVERE, null, ex);
            }
            agent.updateLog(i);
        }
    }
    
}
